<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>角色管理页面</title>
<script type="text/javascript" src="<c:url value='/admin/js/util/jquery-1.8.1.min.js' />" ></script>
<script type="text/javascript" src="<c:url value='/admin/js/util/page.js' />" ></script>
<script type="text/javascript" src="<c:url value='/admin/js/util/common.js' />" ></script>
<script type="text/javascript" src="<c:url value='/admin/js/util/validate.js' />" ></script>
<link href="<c:url value='/admin/css/general.css' />" rel="stylesheet" type="text/css" />
<script language="javascript">
function senfe(o,a,b,c){ 
	var t=document.getElementById(o).getElementsByTagName("tr"); 
	for(var i=0;i<t.length;i++){
		t[i].style.backgroundColor=(t[i].sectionRowIndex%2==0)?a:b; 
		t[i].onmouseover=function(){
			if(this.x!="1")this.style.backgroundColor=c; 
		};
		t[i].onmouseout=function(){
			if(this.x!="1")
				this.style.backgroundColor=(this.sectionRowIndex%2==0)?a:b; 
		};
	} 
}

function queryList() {
	$("#mainForm").attr("action", "<c:url value='/admin/roleAction!list.do' />");
	$("#mainForm").submit();
}

function list(currentPageNO) {
	$("#currentPageNO").val(currentPageNO);
	$("#mainForm").attr("action", "<c:url value='/admin/roleAction!list.do' />");
	$("#mainForm").submit();
}

function prePage(currentPageNO) {
	var prePageNO = getPrePageNO(currentPageNO);
	list(prePageNO);
}

function nextPage(currentPageNO) {
	var totalPage = "${ page.totalPage }";
	var nextPageNO = getNextPageNO(currentPageNO, totalPage);
	list(nextPageNO);
}

function goPage() {
	if(!isInteger("inputPageNo","请输入正确的页码！")) {
		return;
	}
	var inputPageNO = $("#inputPageNo").val();
	var totalPage = "${ page.totalPage }";
	if ((parseInt(inputPageNO) < 1) || (parseInt(inputPageNO) > parseInt(totalPage))) {
		alert("数据不存在！");
		return;
	}
	list(inputPageNO);
}

function goCreatePage() {
	document.location.href="<c:url value='/admin/roleAction!create.do' />";
}

function listTreeMenuPage(roleId) {
	$("#roleId").val(roleId);
	$("#mainForm").attr("action", "<c:url value='/admin/roleAction!treeMenu.do' />");
	$("#mainForm").submit();
}

function deleteObjs() {
	var checkedIds = getCheckBoxValue("pu_checkbox").toString();
	if (checkedIds.length < 1) {
		alert("请选中需要删除的项！");
		return;
	}
	if (confirm('确定删除吗？')){
		$("#checkedIds").val(checkedIds);
		$("#mainForm").attr("action", "<c:url value='/admin/roleAction!delete.do' />");
		$("#mainForm").submit();
	}	
}

function deleteObj(checkedId) {
	if (confirm('确定删除吗？')) {
		$("#checkedIds").val(checkedId);
		$("#mainForm").attr("action", "<c:url value='/admin/roleAction!delete.do' />");
		$("#mainForm").submit();
	}	
}

function editObj(checkedId) {
	$("#checkedIds").val(checkedId);
	$("#mainForm").attr("action", "<c:url value='/admin/roleAction!modify.do' />");
	$("#mainForm").submit();
}

function listMenus(roleId) {
	$("#roleId").val(roleId);
	$("#mainForm").attr("action", "<c:url value='/admin/roleAction!listMenu.do' />");
	$("#mainForm").submit();
}

function viewObj(checkedId) {
	$("#checkedIds").val(checkedId);
	$("#mainForm").attr("action", "<c:url value='/admin/roleAction!view.do' />");
	$("#mainForm").submit();
}
</script>
</head>
<body>
	<form id="mainForm" action="" method="post">
		<input type="hidden" name="pageSize" id="pageSize" value="" />
		<input type="hidden" name="sectionSize" id="sectionSize" value="" />
		<input type="hidden" name="currentPageNO" id="currentPageNO" value="" />
		
		<input type="hidden" name="checkedIds" id="checkedIds" value="" />
		<input type="hidden" name="roleId" id="roleId" value="" />
	
		<div class="tableTitle">
			角色管理
			<ul>
				<li><span><a href="javascript:goCreatePage();"><img src="<c:url value='/admin/images/add.gif'/>" /></a></span><a href="javascript:goCreatePage();">添加</a></li>
				<li><span><a href="javascript:deleteObjs();"><img src="<c:url value='/admin/images/delete.gif'/>" /></a><a href="javascript:deleteObjs();">删除</a></span></li>
			</ul>
		</div>
		<div class="soso">
			<span>搜索选项：</span>角色名称：<input name="role.name" type="text" value="${ role.name }"/> 
			<a href="javascript:queryList();">查找</a>
		</div>
		<table width="100%" cellspacing="1" id="senfe">
			<tr>
				<th width="3%"><input name="c_checkbox" type="checkbox" value="" onclick="changeAllCheckBox('c_checkbox','pu_checkbox')"/></th>
				<th width="30%">角色名</th>
				<th width="30%">角色说明</th>
				<th width="37%">操作</th>
			</tr>
			<c:forEach var="item" items="${roleList}" varStatus="status">
				<tr>
					<td><input name="pu_checkbox" type="checkbox" value="${ item.id }" /></td>
					<td><a href="javascript:viewObj('${ item.id }');">${ item.name }</a></td>
					<td>${ item.remark }</td>
					<td><a href="javascript:listTreeMenuPage('${ item.id }');">菜单权限</a><a href="javascript:editObj('${ item.id }');">修改</a><a href="javascript:deleteObj('${ item.id }');">删除</a></td>
				</tr>
			</c:forEach>
			<tr>
				<td colspan="4">
					<table>
						<tr>
							<td>共有 ${ page.totalRecordSize } 条记录，当前第 ${ page.currentPageNO }/${ page.totalPage } 页</td>
							<td class="tdRight"><a href="javascript:list(1);">首页</a> <a href="javascript:prePage(${ page.currentPageNO });">上一页</a> <a
								href="javascript:nextPage(${ page.currentPageNO });">下一页</a> <a href="javascript:list(${ page.totalPage });">末页</a> 转到第<input id="inputPageNo" type="text" />页
								<a href="javascript:goPage();">GO</a></td>
						</tr>
					</table>
				</td>
			</tr>
		</table>
	</form>
	<script language="javascript">
//senfe("表格名称","奇数行背景","偶数行背景","鼠标经过背景","点击后背景"); 
senfe("senfe","#fff","#F6F6F6","#E1F2F9");
</script>
</body>
</html>
